home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / examples / coldrebt / part01
Encoding:
Internet Message Format  |  1990-05-20  |  7.5 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i169: ColdReboot.s 2 - offcial way to reboot under software control, Part01/01
  5. Message-ID: <12569@xanth.cs.odu.edu>
  6. Date: 20 May 90 21:12:05 GMT
  7. Sender: news@cs.odu.edu
  8. Reply-To: bryce@cbmvax.commodore.com (Bryce Nesbitt)
  9. Lines: 179
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: bryce@cbmvax.commodore.com (Bryce Nesbitt)
  15. Posting-number: Volume 90, Issue 169
  16. Archive-name: examples/coldreboot-2/part01
  17.  
  18. Sometimes applications need to be able to reboot the Amiga under software 
  19. control.  However, rebooting the machine is very tricky, and most attempts 
  20. have been flawed.  ...
  21.  
  22. The ColdReboot() function listed below should be used whenever an application 
  23. needs to reboot the Amiga.  ColdReboot() is the only officially supported way 
  24. to reboot an Amiga under software control. 
  25.  
  26. #!/bin/sh
  27. # This is a shell archive.  Remove anything before this line, then unpack
  28. # it by saving it into a file and typing "sh file".  To overwrite existing
  29. # files, type "sh file -c".  You can also feed this as standard input via
  30. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  31. # will see the following message at the end:
  32. #        "End of archive 1 (of 1)."
  33. # Contents:  coldreboot.s readme
  34. # Wrapped by tadguy@xanth on Sun May 20 17:11:52 1990
  35. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  36. if test -f 'coldreboot.s' -a "${1}" != "-c" ; then 
  37.   echo shar: Will not clobber existing file \"'coldreboot.s'\"
  38. else
  39. echo shar: Extracting \"'coldreboot.s'\" \(2313 characters\)
  40. sed "s/^X//" >'coldreboot.s' <<'END_OF_FILE'
  41. X****************************************************************************
  42. X*
  43. X*   NAME
  44. X*    ColdReboot - Official code to reset any Amiga (Version 2)
  45. X*
  46. X*   SYNOPSIS
  47. X*    ColdReboot()
  48. X*
  49. X*    void ColdReboot(void);
  50. X*
  51. X*   FUNCTION
  52. X*    Reboot the machine.  All external memory and peripherals will be
  53. X*    RESET, and the machine will start its power up diagnostics.
  54. X*
  55. X*   NOTE
  56. X*    Rebooting an Amiga in software is very tricky.    Differing memory
  57. X*    configurations and processor cards require careful treatment.  This
  58. X*    code represents the best available general purpose reset.
  59. X*
  60. X*    The MagicResetCode must be used exactly as specified here. The code
  61. X*    _must_ be longword aligned.  Failure to duplicate the code EXACTLY
  62. X*    may result in improper operation under certain system configurations.
  63. X*
  64. X*   RESULT
  65. X*    This function never returns.
  66. X*
  67. X****************************************************************************
  68. X
  69. X        INCLUDE "exec/types.i"
  70. X        INCLUDE "exec/libraries.i"
  71. X
  72. X        XDEF    _ColdReboot
  73. X        XREF    _LVOSupervisor
  74. X
  75. XABSEXECBASE        EQU 4        ;Pointer to the Exec library base
  76. XMAGIC_ROMEND        EQU $01000000   ;End of Kickstart ROM
  77. XMAGIC_SIZEOFFSET    EQU -$14        ;Offset from end of ROM to Kickstart size
  78. XV36_EXEC        EQU 36        ;Exec with the ColdReboot() function
  79. XTEMP_ColdReboot     EQU -726        ;Offset of the V36 ColdReboot function
  80. X
  81. X
  82. X_ColdReboot:    move.l    ABSEXECBASE,a6
  83. X        cmp.w    #V36_EXEC,LIB_VERSION(a6)
  84. X        blt.s    old_exec
  85. X        jmp    TEMP_ColdReboot(a6)     ;Let Exec do it...
  86. X        ;NOTE: Control flow never returns to here
  87. X
  88. X
  89. X;---- manually reset the Amiga ---------------------------------------------
  90. Xold_exec:    lea.l    GoAway(pc),a5           ;address of code to execute
  91. X        jsr    _LVOSupervisor(a6)      ;trap to code at (a5)...
  92. X        ;NOTE: Control flow never returns to here
  93. X
  94. X
  95. X;-------------- MagicResetCode ---------DO NOT CHANGE-----------------------
  96. X        CNOP    0,4            ;IMPORTANT! Longword align!
  97. XGoAway:     lea.l    MAGIC_ROMEND,a0     ;(end of ROM)
  98. X        sub.l    MAGIC_SIZEOFFSET(a0),a0 ;(end of ROM)-(ROM size)=PC
  99. X        move.l    4(a0),a0                ;Get Initial Program Counter
  100. X        subq.l    #2,a0            ;now points to second RESET
  101. X        reset                ;first RESET instruction
  102. X        jmp    (a0)                    ;CPU Prefetch executes this
  103. X        ;NOTE: the RESET and JMP instructions must share a longword!
  104. X;---------------------------------------DO NOT CHANGE-----------------------
  105. X        END
  106. END_OF_FILE
  107. if test 2313 -ne `wc -c <'coldreboot.s'`; then
  108.     echo shar: \"'coldreboot.s'\" unpacked with wrong size!
  109. fi
  110. # end of 'coldreboot.s'
  111. fi
  112. if test -f 'readme' -a "${1}" != "-c" ; then 
  113.   echo shar: Will not clobber existing file \"'readme'\"
  114. else
  115. echo shar: Extracting \"'readme'\" \(2450 characters\)
  116. sed "s/^X//" >'readme' <<'END_OF_FILE'
  117. X            Amiga Software Reboot, Revisited
  118. X
  119. X                By Bryce Nesbitt
  120. X
  121. X    Copyright 1990 Commodore-Amiga, Inc.  Permission granted to
  122. X    reproduce in full ONLY.  The information contained herein is
  123. X    subject to change without notice, and is provided "as is" without
  124. X    warranty of any kind, either express or implied.  The entire risk
  125. X    as to the use of this information is assumed by the user.
  126. X
  127. X
  128. XSometimes applications need to be able to reboot the Amiga under software 
  129. Xcontrol.  However, rebooting the machine is very tricky, and most attempts 
  130. Xhave been flawed.  The RESET instruction, for example, unconfigures all 
  131. Xmemory; after RESET there is no reliable place to run user code.  Most 
  132. Xreboot code will break whenever the memory or CPU configuration is changed.  
  133. XOther reset code will not work properly on the Amiga 1000.  
  134. X
  135. XIn fact, rebooting the Amiga is so tricky that even the official reboot code 
  136. Xpublished by Commodore will not work in every case. (This article replaces 
  137. X"The Official Way to Software Reboot an Amiga" from the July/August 1989 
  138. Xissue of Amiga Mail, Exec, page III-9.)  Some versions of the A2000 have 
  139. Xa 0.1 uf capacitor (C909) on the hardware reset line.  This capacitor has 
  140. Xthe effect of rejecting short reset pulses, including some of those generated 
  141. Xby the CPU RESET instruction.
  142. X
  143. XThe ColdReboot() function listed below should be used whenever an application 
  144. Xneeds to reboot the Amiga.  ColdReboot() is the only officially supported way 
  145. Xto reboot an Amiga under software control. 
  146. X
  147. XEven this code will fail under some circumstances.  Certain processor cards 
  148. Xdeveloped by Great Valley Products (GVP) lock up when the RESET instruction 
  149. Xis used.  GVP offers an upgrade PAL to fix this problem.  Likewise, if the 
  150. Xuser has a 68020 or 68030 coprocessor card and has copied the Kickstart ROM 
  151. Ximage into 32-bit memory with the command SetCPU FASTROM, the NewReboot() 
  152. Xfunction will not work properly.  To fix this, give the command SetCPU 
  153. XNOFASTROM.
  154. X
  155. XTECHNICAL DESCRIPTION: The code below precalculates a jump address, executes 
  156. Xa RESET instruction, then relies on CPU prefetch to execute the jump.  The 
  157. Xprecalculated jump is constructed to enter the system ROM at the location 
  158. Xof a second RESET instruction.
  159. X
  160. X-- 
  161. X|\_/|  . ACK!, NAK!, EOT!, SOH!
  162. X{o O} .     Bryce Nesbitt, Commodore-Amiga, Inc.
  163. X (")        BIX: bnesbitt
  164. X  U        USENET: bryce@commodore.COM -or- uunet!cbmvax!bryce
  165. XLawyers: America's untapped export market.
  166. END_OF_FILE
  167. if test 2450 -ne `wc -c <'readme'`; then
  168.     echo shar: \"'readme'\" unpacked with wrong size!
  169. fi
  170. # end of 'readme'
  171. fi
  172. echo shar: End of archive 1 \(of 1\).
  173. cp /dev/null ark1isdone
  174. MISSING=""
  175. for I in 1 ; do
  176.     if test ! -f ark${I}isdone ; then
  177.     MISSING="${MISSING} ${I}"
  178.     fi
  179. done
  180. if test "${MISSING}" = "" ; then
  181.     echo You have the archive.
  182.     rm -f ark[1-9]isdone
  183. else
  184.     echo You still need to unpack the following archives:
  185.     echo "        " ${MISSING}
  186. fi
  187. ##  End of shell archive.
  188. exit 0
  189. -- 
  190. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  191. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  192. Post requests for sources, and general discussion to comp.sys.amiga.
  193.